package com.haois.mp.database.module.miniapp.rest;

import com.haois.mp.database.exception.ErrorException;
import com.haois.mp.database.module.remote.service.IGroupService;
import com.haois.mp.database.module.remote.service.IYellowService;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by RuiHaoZ on 2017/12/5.
 */
@RestController
@RequestMapping("/mini/rest/group")
public class GroupMiniController {

    private static final Logger logger = LoggerFactory
            .getLogger(GroupMiniController.class);
    @Autowired
    private IGroupService iGroupService;
    @Autowired
    private IYellowService iYellowService;

    @RequestMapping(value = "/getDepTree", method = RequestMethod.GET)
    public Map getDepTree(String oid, HttpServletRequest request) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iGroupService.getDepTree(oid, access_token);
        return map;
    }
    @RequestMapping(value = "/getGroupList", method = RequestMethod.GET)
    public Map getOrganizeList(HttpServletRequest request,String type) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iGroupService.getGroupList(type,access_token);
        return map;
    }
    @RequestMapping(value = "/getGroupInfo", method = RequestMethod.GET)
    public Map getGroup(String oid, HttpServletRequest request) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iGroupService.getGroup(oid, access_token);
        return map;
    }
    @RequestMapping(value = "/getMobileList")
    public Map toMobile(String oid, HttpServletRequest request) throws WxErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map result = iGroupService.getMemberByOid(oid, access_token);
        return result;
    }
    @RequestMapping(value = "/exitGroup", method = RequestMethod.POST)
    public Map exit(String oid,HttpServletRequest request) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iGroupService.exitGroup(oid,access_token);
        return map;
    }
    @RequestMapping(value = "/getFollowList", method = RequestMethod.GET)
    public Map getFollowList(HttpServletRequest request,String type) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iYellowService.getFollow(access_token);
        return map;
    }
    @RequestMapping(value = "/getAllGroupList", method = RequestMethod.GET)
    public Map getAllGroupList(HttpServletRequest request,String type) throws
            RuntimeException, WxErrorException, ErrorException {
        String access_token = (String) request.getAttribute("access_token");
        Map map = iGroupService.getGroupList(access_token);
        return map;
    }

}
